<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import HeaderNavTabarVue from '@/components/HeaderNavTabar/HeaderNavTabar.vue'
import Folder from '@/static/icon/tongxunlu/companyMoren.png'
import moren from '@/static/icon/tongxunlu/moren.png'
import { getDeptTree } from '@/api/dep'
const cardData = ref([])

onLoad(async (v) => {
  let depId = decodeURIComponent(v.depId)
  let params ={
    pageNum:1,
    pageSize:10000,
    deptId : depId
  }
  let {code,rows} = await getDeptTree(params)
  if(code === 200){
    cardData.value = rows
  }
})

const handleClose = () => {
  uni.switchTab({
    url: '/pages/mine/index',
  })
}

const toInfo = (item)=>{
	console.log(item,'item')
	uni.navigateTo({
		url:`/pages/mine/info/myinfo?data=` + encodeURIComponent(JSON.stringify(item))
	})
}
const copyPhoneNumber = (phoneNumber) => {
  uni.showModal({
    content:'复制手机号码：'+ phoneNumber,//模板中提示的内容
    confirmText:'复制内容',
    success:(res)=>{//点击复制内容的后调函数
      if (res.confirm) {
        uni.setClipboardData({
          data: phoneNumber,//要被复制的内容
          success:()=>{//复制成功的回调函数
            uni.showToast({//提示
              title:'复制成功'
            })
          }
        });
      }

    }})
}
const viewTitle = ref('通讯录')
import config from '@/config'
const serverApiUrl = config.baseUrl
</script>

<template>
  <HeaderNavTabarVue
    :iconFont="'icon-cuowuguanbiquxiao'"
    :title="viewTitle"
    @rightIcon="handleClose"
  />
	<view class="uv-empty" v-if="cardData.length === 0">
		<uv-empty mode="list" icon="../../../static/images/empty.png"></uv-empty>
	</view>
  <view class="detail-box" v-else>
		<!-- @tap="copyPhoneNumber(item.phonenumber)" -->
    <view v-for="(item, index) in cardData" :key="index" class="msg-list" @click="toInfo(item)">
      <view class="list-left">
        <view class="imageWrapper">
          <image :src="serverApiUrl+item.avatar" v-if="item.avatar"></image>
          <image :src="moren" v-else></image>
        </view>
        <view class="list-right">
          <view class="msg-type-author">
            <h4>{{ item.nickName }}</h4>
          </view>
          <text>{{ item.phonenumber }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
@import '@/static/style/index.scss';

.detail-box {
  .time-box {
    margin: 32rpx 24rpx;
    color: #86909c;
    font-size: 24rpx;
    font-style: normal;
    font-weight: 400;
  }

  .msg-list {
    @include flex($align: center, $justify: space-between);
    background-color: #fff;
    height: 108rpx;
    padding: 0 $spacing-row-base;

    &:active {
      background-color: #eff0f2;
    }

    .list-left {
      @include flex($align: center);

      .imageWrapper {
        @include flex($align: center, $justify: space-between);
        // background-color: #e8f3ff;
        // padding: 10rpx;
        margin-right: 16rpx;
        // border-radius: 32rpx;
      }

      image {
        // width: 42rpx;
        // height: 42rpx;
        // border-radius: 50%;
				width: 64rpx;
				height: 64rpx;
				border-radius: 12rpx;
      }

      .msg-type-author {
        @include flex($align: center);

        h4 {
          margin-right: 16rpx;
          color: #000000;
          font-family: 'PingFang SC';
          font-size: 32rpx;
          font-style: normal;
          font-weight: 400;
          line-height: 44.8rpx;
        }

        p {
          text-align: center;
          font-family: 'PingFang SC';
          font-size: 20rpx;
          font-style: normal;
          font-weight: 500;
          padding: 3rpx 8rpx;
          border-radius: 4rpx;
        }
      }

      text {
        align-self: stretch;
        color: #86909c;
        font-family: 'PingFang SC';
        font-size: 24rpx;
        font-style: normal;
        font-weight: 400;
        line-height: 33.6rpx;
        margin-top: 8rpx;
      }
    }

    .time-txt {
      color: #86909c;
      text-align: right;
      font-family: 'PingFang SC';
      font-size: 28rpx;
      font-style: normal;
      font-weight: 400;
      line-height: 39.2rpx;
    }
  }
}
</style>
